@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"
set PROJECT_PATH="%TAO_ROOT%/orbsvcs/tests/FT_Naming/FaultTolerant"
cd %PROJECT_PATH%


::1) Create empty NameService and GroupService directories
rmdir /s /q NameService
rmdir /s /q GroupService

mkdir NameService
mkdir GroupService

@echo off
setlocal

:: 定义要删除的文件列表
set "files=*.err *.out *.ior location1 location2 location3 location4 location5 location6 *.status *.dat"

:: 遍历文件列表并删除存在的文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)

timeout /t 3
::设置ip 和端口 
set "IP_PORT=OMEN_2023:28114" 
echo "==>current ip  and  port is %IP_PORT%"

::2) Start tao_ft_naming
echo "==>Start tao_ft_naming process iiop://%IP_PORT%"
start "tao_ft_naming" cmd /k "%TAO_ROOT%/orbsvcs/FT_Naming_Service/tao_ft_naming -ORBListenEndPoints iiop://%IP_PORT% -ORBDebugLevel 0 -g %PROJECT_PATH%/nm.ior -o %PROJECT_PATH%/ns.ior -v GroupService -u NameService"

timeout /t 3
::3) Start test object server
start "server" cmd /k "server -ORBDefaultInitRef corbaloc:iiop:%IP_PORT% -o %PROJECT_PATH%/srv.ior"

timeout /t 3
::4) Run the test client with the persistence and create arguments
echo  "==>Start client  --persistence --create"
start "client" cmd /k "client --persistence --create -ORBDebugLevel 0 -p corbaloc:iiop:%IP_PORT%/NameService -r corbaloc:iiop:%IP_PORT%/NamingManager -b 4 -d 4"

::5) 先终止掉命名服务
echo  "==>Manually close the terminal tao_ft_naming!!!!"

set /p user_choice=please input(1 to start the tao_ft_naming):

::5) 1、重启命名服务
if "%user_choice%"=="1" (
	echo "==>restart tao_ft_naming"
	start "tao_ft_naming" cmd /k "%TAO_ROOT%/orbsvcs/FT_Naming_Service/tao_ft_naming -ORBListenEndPoints iiop://%IP_PORT% -ORBDebugLevel 0 -g %PROJECT_PATH%/nm.ior -o %PROJECT_PATH%/ns.ior -v GroupService -u NameService"

)
timeout /t 3

::6) 重启客户端 参数有变化 --persistence --validate
set /p user_choice=please input(2 to start the client):
if "%user_choice%"=="2" (
	echo  "==>start client again"
	start "client" cmd /k "client --persistence --validate -ORBDebugLevel 0 -p corbaloc:iiop:%IP_PORT%/NameService -r corbaloc:iiop:%IP_PORT%/NamingManager -b 4 -d 4"
) 

pause >nul

@echo off
